#!/usr/bin/env python

# https://gitee.com/williamzjc/mcp-llm/

import asyncio

from fastmcp import Client

# Set the list of tools
tools = [
        {
            "type": "function",
            "description": "Addition operation",
            "function": {
                "name": "add",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "a": {"type": "number"},
                        "b": {"type": "number"}
                    },
                    "required": ["a", "b"]
                }
            }
        },
        {
            "type": "function",
            "description": "Multiplication operation",
            "function": {
                "name": "multiply",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "a": {"type": "number"},
                        "b": {"type": "number"}
                    },
                    "required": ["a", "b"]
                }
            }
        }
    ]


tool_names = [tool["function"]["name"] for tool in tools]



async def main():
    # endpoint: http://127.0.0.1:8000/app
    async with Client("http://localhost:8000/mcp") as client:

        # Get the name of the function and its arguments
        fn_name = 'add'
        fn_args = {"a":1, "b":3}

        if fn_name in tool_names:
            # Call the function and get the result
            result = await client.call_tool(fn_name, fn_args)
            print(f"System: Model decides to call tool: {fn_name}, the result is {result.content[0].text}.")
        else:
            print("Function not found!")


if __name__ == "__main__":
    asyncio.run(main())

